﻿Public Class MASPOSXRAY
    Dim connect As CONDB = CONDB.NewConnection()
    Private PXRYID = Nothing
    'Private SXRYID = Nothing
    Private PXRYNAME = Nothing
    Private STATUS = Nothing
    Private selectMasposxray = "SELECT `PXRYID` AS 'ID กลุ่ม', `PXRYNAME` AS 'ชื่อกลุ่ม', `STATUS` AS 'สถานะการเปิดใช้งาน' FROM masposxray"
    Property PXRYID_() As Integer
        Get
            Return PXRYID
        End Get
        Set(value As Integer)
            PXRYID = value
        End Set
    End Property
    'Property SXRYID_() As Integer
    '    Get
    '        Return SXRYID
    '    End Get
    '    Set(value As Integer)
    '        SXRYID = value
    '    End Set
    'End Property
    Property PXRYNAME_() As String
        Get
            Return PXRYNAME
        End Get
        Set(value As String)
            PXRYNAME = value
        End Set
    End Property
    Property STATUS_() As Boolean
        Get
            Return STATUS
        End Get
        Set(value As Boolean)
            If value = True Then
                STATUS = 1
            Else
                STATUS = 0
            End If
        End Set
    End Property
    Property selectMasposxray_() As String
        Get
            Return selectMasposxray
        End Get
        Set(value As String)

        End Set
    End Property
    Public Sub loadcombobox(ByVal Masposxraycmb As ComboBox)
        Dim MASPOSXRAY As DataTable
        MASPOSXRAY = connect.GetTable("SELECT `SXRYID`, `SXRYNAME` FROM MASPARTXRAY WHERE `STATUS` = 1 ")
        Try
            With Masposxraycmb
                .DataSource = MASPOSXRAY
                .DisplayMember = "SXRYNAME"
                .ValueMember = "SXRYID"
                '.BindingContext = BindingContext
            End With
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try
    End Sub
    Public Sub insertMasposxrayData()
        If TypeOf PXRYNAME Is String Then
            If connect.GetTable("SELECT `PXRYID` FROM masposxray WHERE `PXRYNAME` = '" & PXRYNAME & "'").Rows.Count > 0 Then
                MsgBox("มีข้อมูลกลุ่มอยู่ในระบบแล้ว", MsgBoxStyle.Critical)
            Else
                Try
                    connect = CONDB.NewConnection()
                    'connectlocal = conlocal.NewConnection()
                    'Dim dischargeID As Integer

                    connect.ExecuteNonQuery("INSERT INTO masposxray (`PXRYNAME`, `STATUS`) VALUES ('" & PXRYNAME & "', '" & STATUS & "')")
                    'dischargeID = connect.ExecuteScalar("INSERT INTO masdischarge (DISCHARGE, STATUS) VALUES ('" & masdischargeDescription & "', '" & masdischargeStatus & "'); SELECT LAST_INSERT_ID();")
                    'connectlocal.ExecuteNonQuery("INSERT INTO MASDISCHARGE (DISCHGID, DISCHARGE, STATUS) VALUES ('" & dischargeID & "', '" & masdischargeDescription & "', '" & masdischargeStatus & "')")
                    MsgBox("ท่านได้ทำการเพิ่มข้อมูลกลุ่มเรียบร้อยแล้ว", MsgBoxStyle.Information)
                Catch ex As Exception
                    MsgBox(vbCrLf & ex.Message)
                End Try
                connect.Dispose()
                'connectlocal.Dispose()
            End If
        Else
            MsgBox("โปรดกรุณาระบุข้อมูลให้ถูกต้อง ต้องเป็นตัวอักษร", MsgBoxStyle.Critical)
        End If
    End Sub

    Public Sub editMasposxrayData()
        If TypeOf PXRYNAME Is String Then

            Try
                connect = CONDB.NewConnection()
                'connectlocal = conlocal.NewConnection()
                connect.ExecuteNonQuery("UPDATE masposxray SET `PXRYNAME` = '" & PXRYNAME & "', `STATUS` = '" & STATUS & "' WHERE `PXRYID` = '" & PXRYID & "'")
                'connectlocal.ExecuteNonQuery("UPDATE MASDISCHARGE SET DISCHARGE = '" & masdischargeDescription & "', STATUS = '" & masdischargeStatus & "' WHERE DISCHGID = '" & masdischargeID & "'")
                MsgBox("ท่านได้ทำการแก้ไขข้อมูลกลุ่มเรียบร้อยแล้ว", MsgBoxStyle.Information)
            Catch ex As Exception
                MsgBox(vbCrLf & ex.Message)
            End Try
            connect.Dispose()
            'connectlocal.Dispose()
        Else
            MsgBox("โปรดกรุณาระบุข้อมูลให้ถูกต้อง ต้องเป็นตัวอักษร", MsgBoxStyle.Critical)
        End If
    End Sub
End Class
